package cn.caskm.souvenirshopsystem.controller.admin;

import cn.caskm.souvenirshopsystem.domain.Result;
import cn.caskm.souvenirshopsystem.domain.dto.PageDTO;
import cn.caskm.souvenirshopsystem.domain.po.Goods;
import cn.caskm.souvenirshopsystem.domain.query.AdminGoodsQuery;
import cn.caskm.souvenirshopsystem.domain.vo.AdminGoodsListVO;
import cn.caskm.souvenirshopsystem.service.GoodsService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/goods")
@RequiredArgsConstructor
public class AdminGoodsController {

    private final GoodsService goodsService;

    @GetMapping("/page")
    public Result<PageDTO<AdminGoodsListVO>> page(AdminGoodsQuery query) {
        return goodsService.page(query);
    }
    
    @GetMapping("/list")
    public Result<List<Goods>> list() {
        return goodsService.getAll();
    }

    @GetMapping("/detail/{id}")
    public Result<Goods> detail(@PathVariable("id") Integer id) {
        return goodsService.detail(id);
    }

    @PostMapping("/saveOrUpdate")
    public Result<Object> saveOrUpdate(@RequestBody Goods goods) {
        goodsService.saveOrUpdateEntity(goods);
        return Result.success();
    }

    @DeleteMapping("/deleteById/{id}")
    public Result<Object> deleteById(@PathVariable("id") Integer id) {
        goodsService.removeById(id);
        return Result.success();
    }
} 